package com.bins.code.generator.strategy.impl;

import com.bins.code.generator.config.builder.ConfigBuilder;
import com.bins.code.generator.enums.TemplateEnum;
import com.bins.code.generator.model.PageDtoModel;
import com.bins.code.generator.model.po.TableInfo;
import com.bins.code.generator.strategy.IGenerator;
import org.springframework.beans.BeanUtils;

public class PageDtoGenerator extends AbstractStrategyGenerator implements IGenerator {

    private static final PageDtoGenerator generator = new PageDtoGenerator();

    private PageDtoGenerator() {
    }

    public static PageDtoGenerator getInstance() {
        return generator;
    }

    private PageDtoModel model;

    @Override
    public String getGeneratorName() {
        return TemplateEnum.PAGE_DTO.getCode();
    }

    @Override
    public void initModel(TableInfo tableInfo) {
        ConfigBuilder configBuilder = super.getConfigBuilder();
        model = new PageDtoModel(configBuilder);
        BeanUtils.copyProperties(configBuilder.getStrategyConfig().pageDtoBuilder().get(), model);
        model.initCommonConfig();
        model.setTableComment("分页dto父类");
        model.setClassName("PageDto");
        model.setCommonPackage(configBuilder.getPackageConfig().getPackageInfo().get(TemplateEnum.COMMON.getContent()));
    }

    public PageDtoModel getModel() {
        return model;
    }

    @Override
    public String getTemplateCode() {
        return model.getTemplate().getCode();
    }

    @Override
    public String getModelFileName() {
        return model.getClassName();
    }

    @Override
    public String getModelTemplatePath() {
        return getConfigBuilder().getTemplateConfig().getPageDto();
    }

    @Override
    public TemplateEnum getModelTemplate() {
        return model.getTemplate();
    }
}
